from datetime import datetime

from django.http import HttpResponse
from django.shortcuts import redirect, render
from django.urls import reverse


def demo(request):
    print(request)
    print("hello Django")
    return HttpResponse("返回HttpResponse对象")
data = {
        "python": [
            {
                'title': '【Python】NumPy（一）：数据类型、创建数组及基本操作',
                'desc': '本篇介绍了什么是numpy，以及numpy中的数据类型，如何使用NumPy来创建数组，创建数组的7种方式，以及数组的一些基本操作。',
                'detail': 'https://blog.csdn.net/zhyhgx/article/details/143017888?spm=1001.2100.3001.7377&utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-1-143017888-null-null.nonecase&depth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-1-143017888-null-null.nonecase',
                'img': 'https://i-blog.csdnimg.cn/direct/6d114b5e0e634c7c8b29aacd1483d0ad.png?x-oss-process=image/resize,m_fixed,h_300,image/format,png',
                'create_time': datetime(2024,10,8,15,16)
            },
            {
                'title': 'Python酷库之旅-第三方库Pandas(181)',
                'desc': '第三方库Pandas(181)',
                'detail': 'https://blog.csdn.net/ygb_1024/article/details/143352388?spm=1001.2100.3001.7377&utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-3-143352388-null-null.nonecase&depth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-3-143352388-null-null.nonecase',
                'img': 'https://img-blog.csdnimg.cn/img_convert/fad536e972e14ce4b37803185dc3b00c.png?x-oss-process=image/resize,m_fixed,h_300,image/format,png','create_time': datetime(2024,11,8,15,16)
            },
            {
                'title': 'python安卓自动化pyaibote实践------学习通自动刷课',
                'desc': 'pyaibote安卓自动化实战，学习通刷课脚本',
                'detail': 'https://blog.csdn.net/2302_79590880/article/details/138360025?spm=1001.2100.3001.7377&utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-4-138360025-null-null.nonecase&depth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-4-138360025-null-null.nonecase',
                'img': 'https://img-blog.csdnimg.cn/direct/e5914924856742b8a8be94f4b60deb6d.jpeg?x-oss-process=image/resize,m_fixed,h_300,image/format,png','create_time': datetime(2024,11,8,6,16)
            }],
        "java": [
            {
                'title': '【JavaSE】【多线程】线程池',
                'desc': '线程池',
                'detail': 'https://blog.csdn.net/yj20040627/article/details/143282442?spm=1001.2100.3001.7377&utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-1-143282442-null-null.nonecase&depth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-1-143282442-null-null.nonecase',
                'img': 'https://i-blog.csdnimg.cn/direct/ddc6897d72474fb1ba598f55e0027dee.png?x-oss-process=image/resize,m_fixed,h_300,image/format,png','create_time': datetime(2024,11,8,10,16)
            },
            {
                'title': 'Java 多线程（三）—— 死锁',
                'desc': 'Java 死锁问题与解决方案',
                'detail': 'https://blog.csdn.net/liwuqianhzc/article/details/142959410?spm=1001.2100.3001.7377&utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-3-142959410-null-null.nonecase&depth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-3-142959410-null-null.nonecase',
                'img': 'https://i-blog.csdnimg.cn/direct/95e9053a24f542eb8c5abe55d5f153fe.png?x-oss-process=image/resize,m_fixed,h_300,image/format,png','create_time': datetime(2024,9,8,15,16)
            },
            {
                'title': '【JavaSE】【多线程】volatile,wait/notify',
                'desc': 'volatile处理内存可见性问题wait / notify调控线程调度',
                'detail': 'https://blog.csdn.net/yj20040627/article/details/142694133?spm=1001.2100.3001.7377&utm_medium=distribute.pc_feed_blog_category.none-task-blog-classify_tag-5-142694133-null-null.nonecase&depth_1-utm_source=distribute.pc_feed_blog_category.none-task-blog-classify_tag-5-142694133-null-null.nonecase',
                'img': 'https://i-blog.csdnimg.cn/direct/46687258a85941fbabcada13902e1d88.png?x-oss-process=image/resize,m_fixed,h_300,image/format,png','create_time': datetime(2024,11,1,15,16)
            }],
        'ai':[]
    }
# user={
#     'name': 'moji',
#     'sex': 'boy',
#     'age': 18
# }
user=None


def test(request, **kwargs):
    classes = kwargs.get('nav')
    if classes not in list(data.keys()):
        return redirect(reverse('not_fount'))
    res = data.get(classes)
    # if not res:
    #     return redirect(reverse('not_fount'))
    # 通过context参数传值，并且以字典的形式传值
    return HttpResponse(render(request, 'demo/demo.html', context={
        'res': res,
        'dd': data.keys(),
        'data': classes,
        'user': user
    }))


def test1(request):
    return HttpResponse('页面找不到了~~~')

def index(request):
    return HttpResponse(render(request, 'demo/index.html', context={
        'dd': data.keys(),
        'user': user
    }))

